//
//  MyAttentionTableViewCell.m
//  Findif
//
//  Created by Mac on 2018/11/8.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "MyAttentionTableViewCell.h"

@interface MyAttentionTableViewCell ()

@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * exploreLabel;
@property (nonatomic, weak)UIButton * stateButton;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, copy)NSString * ID;

@end

@implementation MyAttentionTableViewCell


- (void)setModel:(MyAttentionModel *)model{
    
    _model = model;
    
    self.ID = model.attention_user_id;
    self.nameLabel.text = model.attention_user_name;
    if (model.personality_sign) {
        
        self.exploreLabel.text = [NSString stringWithFormat:@"个性签名:%@",model.personality_sign];
    }else{
        
        self.exploreLabel.text = @"这个人很懒什么都没留下~~";
    }
    if ([model.head_img containsString:@"http"]) {
        
        NSURL * url = [NSURL URLWithString:model.head_img];
        [self.iconImageView sd_setImageWithURL:url];
    } else {
        
        NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,model.head_img];
        NSURL * url = [NSURL URLWithString:imgStr];
        [self.iconImageView sd_setImageWithURL:url];
    }
    int is_each = [model.is_each intValue];
    if (is_each == 1) {
        
        self.stateButton.selected = YES;
    }else{
        
        self.stateButton.selected = NO;
    }
}


- (void)setSearchModel:(SearchPersonModel *)searchModel{
    
    _searchModel = searchModel;
    
    self.nameLabel.text = searchModel.user_name;
    if (searchModel.personality_sign) {
        
        self.exploreLabel.text = [NSString stringWithFormat:@"个性签名:%@",searchModel.personality_sign];
    }else{
        
        self.exploreLabel.text = @"这个人很懒什么都没留下~~";
    }
    
    if ([searchModel.head_img containsString:@"http"]) {
        
        NSURL * url = [NSURL URLWithString:searchModel.head_img];
        [self.iconImageView sd_setImageWithURL:url];
    } else {
        
        NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,searchModel.head_img];
        NSURL * url = [NSURL URLWithString:imgStr];
        [self.iconImageView sd_setImageWithURL:url];
    }
    
    self.stateButton.hidden = YES;
    
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ZRWhiteColor;
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.image = [UIImage imageNamed:@"组12"];
    iconImageView.layer.cornerRadius = 22.5 * SCREENH6;
    iconImageView.layer.masksToBounds = YES;
    
    self.iconImageView = iconImageView;
    
    [self.contentView addSubview:self.iconImageView];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.text = @"用户姓名";
    nameLabel.textColor = ZRBlackColor;
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.nameLabel = nameLabel;
    
    [self.contentView addSubview:self.nameLabel];
    
    
    UILabel * exploreLabel = [UILabel new];
    
    exploreLabel.text = @"个性签名：我在秋分里等你，阿萨德被踩死暗杀计划部分参考啊";
    exploreLabel.textColor = [UIColor lightGrayColor];
    exploreLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.exploreLabel = exploreLabel;
    
    [self.contentView addSubview:self.exploreLabel];
    
    
    UIButton * stateButton = [UIButton new];
    
    [stateButton setTitle:@"关注" forState:UIControlStateNormal];
    [stateButton setTitle:@"互关" forState:UIControlStateSelected];
    [stateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [stateButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];
    [stateButton setImage:[UIImage imageNamed:@"已关注"] forState:UIControlStateNormal];
    [stateButton setImage:[UIImage imageNamed:@"互关"] forState:UIControlStateSelected];
    [stateButton addTarget:self action:@selector(clickStateButton:) forControlEvents:UIControlEventTouchUpInside];
    stateButton.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    stateButton.layer.cornerRadius = 5;
    stateButton.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    stateButton.layer.borderWidth = 1 * SCREENH6;
    stateButton.layer.masksToBounds = YES;
    
    self.stateButton = stateButton;
    
    [self.contentView addSubview:self.stateButton];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xF7F8F9);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
    
}

- (void)layoutSubviews{
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(10 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(10 * SCREENH6);
        make.height.width.mas_equalTo(45 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconImageView);
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.stateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.contentView).offset(-10 * SCREENH6);
        make.centerY.mas_equalTo(self.iconImageView);
        make.height.mas_equalTo(30 * SCREENH6);
        make.width.mas_equalTo(60 * SCREENH6);
    }];
    
    [self.exploreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.trailing.mas_equalTo(self.stateButton.mas_leading).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(5 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView);
        make.trailing.mas_equalTo(self.stateButton);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
}

- (void)clickStateButton:(UIButton *)button{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickItemID:)])
    {
        [self.delegate clickItemID:self.ID];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
